//
//  AMBaseTableViewController.swift
//  微博
//
//  Created by zhc on 15/11/23.
//  Copyright © 2015年 zhc. All rights reserved.
//

import UIKit

class AMBaseTableViewController: UITableViewController {

  var userlogin = false
    
    
    override func loadView() {
        userlogin ? super.loadView() : setupVistorView()
    }
    
    
    
    private func setupVistorView(){
        
        //设置代理
        
        vistorView.AMVVdelegate=self
        
      // view = AMVistorView()
        view = vistorView
       // view.backgroundColor=UIColor(white: 237/255, alpha: 1)
       
        //监听应用退到后台
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
        
        //回到前台
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didbecomeactive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        
        
        if self is AMHomeTableViewController{
         
            //如果是首页就开始转动
            vistorView.startRotationAnimation()
            
         
        }else if self is AMmessageTableViewController{
      
            
            print("2")
            vistorView.setupVistorView("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        
        }else if self is AMProfileTableViewController{
        
           vistorView.setupVistorView("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is AMdiscoverTableViewController{
        
             vistorView.setupVistorView("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        
        
        }
        
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
        
        
   
    }
    
    //移除通知
    deinit{
      //移除通知
        if self is AMHomeTableViewController{
        
        NSNotificationCenter.defaultCenter().removeObserver(self)
        
        }
    
    }
    
    
    
    
    
    //懒加载访客视图，不然没有办法调用方法
    private lazy var vistorView: AMVistorView = AMVistorView()
    
    
    
    func didEnterBackground(){
       vistorView.pauseAnimation()
    
    }
    func didbecomeactive(){
        vistorView.resumeAnimation()
    
    }
    

}


//统一管理协议方法
extension AMBaseTableViewController: AMVistorViewDelegate{
    
    func vistorViewLoginClick(){
        
        print("登陆按钮点击")
        
        let oauthVC = AMOauthViewController()
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
        
        
    }
    
}



